{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     con: array([1.80713222e-09])\n",
      "     fun: -14.57142856564506\n",
      " message: 'Optimization terminated successfully.'\n",
      "     nit: 5\n",
      "   slack: array([-2.24583019e-10,  3.85714286e+00])\n",
      "  status: 0\n",
      " success: True\n",
      "       x: array([6.42857143e+00, 5.71428571e-01, 2.35900788e-10])\n",
      "[6.42857143e+00 5.71428571e-01 2.35900788e-10]\n"
     ]
    }
   ],
   "source": [
    "import scipy.optimize\n",
    "\n",
    "# document: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linprog.html#scipy.optimize.linprog\n",
    "# function name: scipy.optimize.linprog\n",
    "# function: linear programming.\n",
    "# 例1.2的程序\n",
    "c = [2, 3, -5]\n",
    "A_ub = [[-2, 5, -1],\n",
    "        [1, 3, 1]]\n",
    "b_ub = [-10, 12]\n",
    "A_eq = [[1, 1, 1]]\n",
    "b_eq = [7]\n",
    "bounds = [(0, None), (0, None), (0, None)]\n",
    "res = scipy.optimize.linprog(c=[-x for x in c], A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=bounds)\n",
    "print(res)\n",
    "print(res.get('x'))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
